package com.ssy.lingxi.purchase.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.purchase.model.bo.FileUploadBO;
import com.ssy.lingxi.purchase.model.convert.JpaJsonToFileUploadVOConverter;
import com.ssy.lingxi.purchase.model.vo.FileUploadVO;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * 采购请购单实体类
 * @author wyx
 * @version 2.0.0
 * @date 2021-10-27
 */
@Entity
@Table(schema = "public", name = "pu_purchase_requisition",
        indexes = {@Index(name = "pu_requisition_buyer_member_id_buyer_role_id_idx", columnList = "buyerMemberId,buyerRoleId"),
                @Index(name = "pu_requisition_vendor_member_id_vendor_role_id_idx", columnList = "vendorMemberId,vendorRoleId"),
                @Index(name = "pu_requisition_buyer_member_name_idx", columnList = "buyerMemberName"),
                @Index(name = "pu_requisition_vendor_member_name_idx", columnList = "vendorMemberName"),
                @Index(name = "pu_requisition_requisition_no_idx", columnList = "requisitionNo"),
                @Index(name = "pu_requisition_buyer_inner_status_idx", columnList = "buyerInnerStatus")})
public class PurchaseRequisition implements Serializable {
    private static final long serialVersionUID = 5940030544558120937L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pu_purchase_requisition_seq")
    @SequenceGenerator(sequenceName = "pu_purchase_requisition_seq", name = "pu_purchase_requisition_seq", allocationSize = 1)
    private Long id;

    /**
     * 创建时间（下单时间）
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 创建人
     */
    @Column(columnDefinition = "varchar(30)")
    private String creator;

    /**
     * 订单预交日期，格式为yyyy-MM-dd
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime deliverTime;

    /**
     * 买方（采购）会员Id
     */
    @Column
    private Long buyerMemberId;

    /**
     * 采购会员角色Id
     */
    @Column
    private Long buyerRoleId;

    /**
     * 采购会员名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String buyerMemberName;

    /**
     * 卖方（供应）会员Id
     */
    @Column
    private Long vendorMemberId;

    /**
     * 卖方（供应）会员角色Id
     */
    @Column
    private Long vendorRoleId;

    /**
     * 卖方（供应）会员（店铺）名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String vendorMemberName;

    /**
     * 请购单编号
     */
    @Column(columnDefinition = "varchar(20)")
    private String requisitionNo;

    /**
     * 摘要
     */
    @Column(columnDefinition = "varchar(100)")
    private String digest;

    /**
     * 部门ID
     */
    @Column
    private Long departmentId;

    /**
     * 部门名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String department;

    /**
     * 用途
     */
    @Column(columnDefinition = "varchar(100)")
    private String purpose;

    /**
     * 订单商品总金额 = 商品单价 * 数量
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal productAmount;

    /**
     * 采购商内部状态，定义在 RequisitionInnerStatusEnum 中
     */
    @Column
    private Integer buyerInnerStatus;

    /**
     * 请购总数量
     */
    @Column(columnDefinition = "numeric(15,1)")
    private BigDecimal quantity;

    /**
     * 已转采购订单总数量
     */
    @Column(columnDefinition = "numeric(15,1)")
    private BigDecimal transferQuantity;

    /**
     * 请购人ID
     */
    @Column
    private Long requisitionerId;

    /**
     * 请购人名称
     */
    @Column
    private String requisitioner;

    /**
     * 附件
     */
    @Convert(converter = JpaJsonToFileUploadVOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<FileUploadVO> attachments ;

    /**
     * 预交日期
     */
    @Column
    private String advanceDeliveryDate;

    /**
     * 配送方式 ,定义在 DeliveryMethodEnum 中
     */
    @Column
    private Integer deliveryMethod;

    /**
     * 直送客户/客户自提 ,定义在 DeliveryTypeEnum 中
     */
    @Column
    private Integer deliveryType;

    /**
     * 送货地址
     */
    @Column
    private String deliveryAddress;

    /**
     * 送货地址id
     */
    @Column
    private Long deliveryAddressId;

    /**
     * 一对多双向关联订单物料
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "purchaseRequisition", cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, fetch = FetchType.LAZY)
    private Set<PurchaseProduct> products;

    /**
     * 一对一单向关联流程任务
     */
    @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinColumn(name = "task_id", referencedColumnName = "id")
    private PurchaseProcessTask task;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public LocalDateTime getDeliverTime() {
        return deliverTime;
    }

    public void setDeliverTime(LocalDateTime deliverTime) {
        this.deliverTime = deliverTime;
    }

    public Long getBuyerMemberId() {
        return buyerMemberId;
    }

    public void setBuyerMemberId(Long buyerMemberId) {
        this.buyerMemberId = buyerMemberId;
    }

    public Long getBuyerRoleId() {
        return buyerRoleId;
    }

    public void setBuyerRoleId(Long buyerRoleId) {
        this.buyerRoleId = buyerRoleId;
    }

    public String getBuyerMemberName() {
        return buyerMemberName;
    }

    public void setBuyerMemberName(String buyerMemberName) {
        this.buyerMemberName = buyerMemberName;
    }

    public Long getVendorMemberId() {
        return vendorMemberId;
    }

    public void setVendorMemberId(Long vendorMemberId) {
        this.vendorMemberId = vendorMemberId;
    }

    public Long getVendorRoleId() {
        return vendorRoleId;
    }

    public void setVendorRoleId(Long vendorRoleId) {
        this.vendorRoleId = vendorRoleId;
    }

    public String getVendorMemberName() {
        return vendorMemberName;
    }

    public void setVendorMemberName(String vendorMemberName) {
        this.vendorMemberName = vendorMemberName;
    }

    public String getRequisitionNo() {
        return requisitionNo;
    }

    public void setRequisitionNo(String requisitionNo) {
        this.requisitionNo = requisitionNo;
    }

    public String getDigest() {
        return digest;
    }

    public void setDigest(String digest) {
        this.digest = digest;
    }

    public Long getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Long departmentId) {
        this.departmentId = departmentId;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getPurpose() {
        return purpose;
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    public BigDecimal getProductAmount() {
        return productAmount;
    }

    public void setProductAmount(BigDecimal productAmount) {
        this.productAmount = productAmount;
    }

    public Integer getBuyerInnerStatus() {
        return buyerInnerStatus;
    }

    public void setBuyerInnerStatus(Integer buyerInnerStatus) {
        this.buyerInnerStatus = buyerInnerStatus;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public BigDecimal getTransferQuantity() {
        return transferQuantity;
    }

    public void setTransferQuantity(BigDecimal transferQuantity) {
        this.transferQuantity = transferQuantity;
    }

    public Long getRequisitionerId() {
        return requisitionerId;
    }

    public void setRequisitionerId(Long requisitionerId) {
        this.requisitionerId = requisitionerId;
    }

    public String getRequisitioner() {
        return requisitioner;
    }

    public void setRequisitioner(String requisitioner) {
        this.requisitioner = requisitioner;
    }

    public List<FileUploadVO> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<FileUploadVO> attachments) {
        this.attachments = attachments;
    }

    public String getAdvanceDeliveryDate() {
        return advanceDeliveryDate;
    }

    public void setAdvanceDeliveryDate(String advanceDeliveryDate) {
        this.advanceDeliveryDate = advanceDeliveryDate;
    }

    public Integer getDeliveryMethod() {
        return deliveryMethod;
    }

    public void setDeliveryMethod(Integer deliveryMethod) {
        this.deliveryMethod = deliveryMethod;
    }

    public String getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public Long getDeliveryAddressId() {
        return deliveryAddressId;
    }

    public void setDeliveryAddressId(Long deliveryAddressId) {
        this.deliveryAddressId = deliveryAddressId;
    }

    public Set<PurchaseProduct> getProducts() {
        return products;
    }

    public void setProducts(Set<PurchaseProduct> products) {
        this.products = products;
    }

    public PurchaseProcessTask getTask() {
        return task;
    }

    public void setTask(PurchaseProcessTask task) {
        this.task = task;
    }

    public Integer getDeliveryType() {
        return deliveryType;
    }

    public void setDeliveryType(Integer deliveryType) {
        this.deliveryType = deliveryType;
    }
}